package com.szh.te.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.szh.te.service.GoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping
@Slf4j
public class TestController {

    @Resource
    private GoodService goodService;

    @GetMapping("/testLoadBalancerCode")
    public String testLoadBalancerCode() {
        log.error("啦啦啦啦啦");
        return "hello";
    }
    
    @GetMapping("/testJavaDate")
    public String testJavaDate(@RequestParam("date")Date date,@RequestParam("name") String name){
        return "javaDate";
    }

    @GetMapping("/testHuToolDate")
    public String testHuToolDate(Date date, String name){
        return "javaDate";
    }

    @SentinelResource("hot")
    @GetMapping("/order/{orderId}")
    public void getOrderId(@PathVariable("orderId") Long orderId) throws BlockException {
        if (orderId == 1) {
            try {
                Thread.sleep(60);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        log.error("OrderId = {}", orderId);
    }

    @GetMapping("/read")
    public String read() {
        return "read";
    }

    @GetMapping("/write")
    public String write() {
        return "write";
    }

    @GetMapping("/order/query")
    public void queryOrder() {
        goodService.queryGoods();
        log.error("查询订单");
    }

    @GetMapping("/order/save")
    public void saveOrder() {
        goodService.queryGoods();
        log.info("保存订单");
    }
}
